package com.lframework.xingyun.basedata.impl.coupon;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lframework.starter.web.core.impl.BaseMpServiceImpl;
import com.lframework.starter.web.core.utils.PageResultUtil;
import com.lframework.starter.web.core.components.resp.PageResult;
import java.io.Serializable;
import com.lframework.starter.common.utils.Assert;
import com.lframework.xingyun.basedata.bo.coupon.QueryCouponStopBo;
import com.lframework.xingyun.basedata.entity.CouponStop;
import com.lframework.xingyun.basedata.mappers.CouponStopMapper;
import com.lframework.xingyun.basedata.service.coupon.CouponStopService;
import com.lframework.xingyun.basedata.vo.coupon.QueryCouponStopVo;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CouponStopServiceImpl extends BaseMpServiceImpl<CouponStopMapper, CouponStop> implements CouponStopService {

    @Override
    public PageResult<QueryCouponStopBo> queryPage(Integer pageIndex, Integer pageSize, QueryCouponStopVo vo) {

        Assert.greaterThanZero(pageIndex);
        Assert.greaterThanZero(pageSize);

        IPage<QueryCouponStopBo> page = this.baseMapper.queryPage(vo);

        return PageResultUtil.convert(page);
    }

    @Override
    public List<QueryCouponStopBo> queryList(QueryCouponStopVo vo) {
        return this.baseMapper.queryList(vo);
    }

    @Cacheable(value = CouponStop.CACHE_NAME, key = "@cacheVariables.tenantId() + #id", unless = "#result == null")
    @Override
    public CouponStop findById(String id) {

        return getBaseMapper().selectById(id);
    }

    @CacheEvict(value = CouponStop.CACHE_NAME, key = "@cacheVariables.tenantId() + #key")
    @Override
    public void cleanCacheByKey(Serializable key) {

    }
}

